﻿using Abp.AutoMapper;
using Abp.Modules;
using Abp.Reflection.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Hosting;
using System;
using FwProject.PublicService;
using FwProject.PublicService.JPush;

namespace FwProject
{
       [DependsOn(
        typeof(FwProjectCoreModule),
        typeof(AbpAutoMapperModule))]
    public class FwProjectPublicServiceModule : AbpModule
    {
        private readonly IHostingEnvironment _env;
        private readonly IConfigurationRoot _appConfiguration;

        public FwProjectPublicServiceModule(IHostingEnvironment env)
        {
            _env = env;
            _appConfiguration= _env.GetAppConfiguration();
        }
        public override void PreInitialize()
        {
            JPushModel();
        }
        public override void Initialize()
        {
            var thisAssembly = typeof(FwProjectPublicServiceModule).GetAssembly();
            IocManager.RegisterAssemblyByConvention(thisAssembly);
        }
        /// <summary>
        /// 绑定推送信息
        /// </summary>
        private void JPushModel()
        {

            IocManager.Register<JPushConfig>();
            var tokenAuthConfig = IocManager.Resolve<JPushConfig>();
            tokenAuthConfig.IsEnabled = Convert.ToBoolean(_appConfiguration["JPush:JPushModel:IsEnabled"]);
            tokenAuthConfig.AppKey = _appConfiguration["JPush:JPushModel:AppKey"];
            tokenAuthConfig.AppSecret = _appConfiguration["JPush:JPushModel:AppSecret"];

        }
    }
}
